package com.jic.data.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.date.DateUtil;
import com.jic.data.constant.consist.ResponseCode;
import com.jic.data.exception.AppRuntimeException;
import com.jic.data.model.vo.response.HistogramChartResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
//import com.github.pagehelper.Page;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
import java.math.BigDecimal;
//import com.jic.sign.platform.common.exception.AppRuntimeException;
//import com.jic.sign.platform.common.constant.ResponseCode;
import com.jic.data.model.vo.response.MonSingleSaleAmountResponse;
import com.jic.data.model.entity.MonSingleSaleAmount;
import com.jic.data.mapper.MonSingleSaleAmountMapper;
import com.jic.data.service.MonSingleSaleAmountService;

import lombok.extern.slf4j.Slf4j;
/**
 * 接口实现类
 *
 * @author : 建投数据科技(山东)有限公司
 * @version : v1.0.0
 * @email :
 * @since : 2020-03-09 10:12:20
 */
@Service
@Slf4j
public class MonSingleSaleAmountServiceImpl implements MonSingleSaleAmountService {

	@Resource
	private MonSingleSaleAmountMapper mapper;


	/**
	 * 月度商品销售额&件单价
	 *
	 * @param request 不分页查询入参实体类
	 * @return 数据库查到的实体类列表
	 */
	@Override
	public HistogramChartResponse listAllRecord(MonSingleSaleAmount request) {
		List<MonSingleSaleAmount> list = mapper.selectBySelective(request);

		HistogramChartResponse response = new HistogramChartResponse();
		List<String> xDate = new ArrayList<>();
		List<Double> saleAmount = new ArrayList<>();
		List<Double> unitPrice = new ArrayList<>();

		list.stream().forEach(amount -> {
			xDate.add(DateUtil.format(amount.getSaleDate(),"yyyy年MM月"));
			saleAmount.add(amount.getTotalSaleAmount().doubleValue());
			unitPrice.add(amount.getOnePiecesUnitPrice().doubleValue());
		});
		response.setX(xDate);
		response.setY1(saleAmount);
		response.setY2(unitPrice);

		return response;

	}




}
